﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace PlanTask
{
    public class Program
    {
        static void Main(string[] args)
        {
            //策划报费提醒，每月25日做提醒

            #region 查询数据库
            string sSql = "select Project_NO,Project_Business,Project_BusinessCode  from  t_Project where Project_ID in(select Project_EarlyPlot_MainID from t_Project_EarlyPlot where  Project_EarlyPlot_MainID in(select Project_ProjectCommission_ProjectID from t_Project_Confirmation,t_Project_ProjectCommission where t_Project_Confirmation.Project_Confirmation_CommissionID=t_Project_ProjectCommission.Project_ProjectCommission_ID and t_Project_ProjectCommission.Project_ProjectCommission_AgentID=1 group by Project_ProjectCommission_ProjectID having SUM(isnull(Project_Confirmation_PartCommission,0))<t_Project_EarlyPlot.Project_EarlyPlot_Fees))";
            SqlCommand cmdToExecute = new SqlCommand();
            SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
            SqlConnection con = new SqlConnection(@"data source=gzs-ecc04\sql2008;initial catalog=DB_EcSalseManage;UID=gzsystem;PWD=gzsoft!@#1029");
            DataSet ds = new DataSet();

            cmdToExecute.CommandText = sSql;
            cmdToExecute.CommandType = CommandType.Text;

            try
            {
                cmdToExecute.Connection = con;
                con.Open();

                adapter.Fill(ds);

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                con.Close();

                cmdToExecute.Dispose();

                adapter.Dispose();
            }
            #endregion

            DataTable dt = ds.Tables[0];

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                //string sDirecter = dt.Rows[i]["Project_Directer"].ToString();
                //string sDirecterCode = dt.Rows[i]["Project_DirecterCode"].ToString();
                //EcSalseManage.App_Code.CommonFunction.SendMessage(sDirecter, sDirecterCode, "测试123", "123");

                //string sDirecter1Code = dt.Rows[i]["Project_Directer1Code"].ToString();
                //string sDirecter1 = dt.Rows[i]["Project_Directer1"].ToString();
                //EcSalseManage.App_Code.CommonFunction.SendMessage(sDirecter1, sDirecter1Code, "测试123", "123");


                //string sManagerCode = dt.Rows[i]["Project_ManagerCode"].ToString();
                //string sManager = dt.Rows[i]["Project_Manager"].ToString();
                //EcSalseManage.App_Code.CommonFunction.SendMessage(sManager, sManagerCode, "测试123", "123");

                string sTitle = "请注意，项目编号：" + dt.Rows[i]["Project_NO"].ToString() + " 需要您的审核";
                string sBody = "请注意，项目编号：" + dt.Rows[i]["Project_NO"].ToString() + " 需要您的审核";
                string sBusiness = dt.Rows[i]["Project_Business"].ToString();
                string sBusinessCode = dt.Rows[i]["Project_BusinessCode"].ToString();
                EcSalseManage.App_Code.CommonFunction.SendMessage(sBusiness, sBusinessCode, sTitle, sBody);


                //string sDepartmentHead = dt.Rows[i]["Project_DepartmentHead"].ToString();
                //string sDepartmentHeadCode = dt.Rows[i]["Project_DepartmentHeadCode"].ToString();
                //EcSalseManage.App_Code.CommonFunction.SendMessage(sDepartmentHead, sDepartmentHeadCode, "测试123", "123");
            }
        }


   
    }
}
